-
-
Notifications
You must be signed in to change notification settings - Fork 252
perf(multichain): batch OnAsset*
requests
#6886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
a706278
to
468843a
Compare
@metamaskbot publish-preview |
// Apply these updated rates to controller state | ||
this.#applyUpdatedRates(rates); | ||
for (const asset of this.#getAssetsForAccount(account.id)) { | ||
assetToSnapID.set(asset, snapId as SnapId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe simpler to construct the Snap ID -> Asset List mapping here instead of constructing this mapping and then constructing the reverse mapping in the next function call?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did in two steps mainly because it also dedupes the assets. If I build the snapId -> assets[] mapping here I need to do another pass to remove the deplicates of each entry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use a Snap ID -> Asset Set for that perhaps? Up to you!
...es/assets-controllers/src/MultichainAssetsRatesController/MultichainAssetsRatesController.ts
Outdated
Show resolved
Hide resolved
...es/assets-controllers/src/MultichainAssetsRatesController/MultichainAssetsRatesController.ts
Outdated
Show resolved
Hide resolved
if (assets?.length === 0) { | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep this? So we don't create sets for Snaps that don't have any assets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I added some checks to prevent adding empty sets to the map, or calling the Snap when the list of assets is empty.
Explanation
Currently,
OnAssetConversion
andOnAssetMarketData
requests are batched per account, which can lead to duplicate requests when an asset is present in multiple accounts.This PR resolves this issue by batching the requests per Snap for all assets managed by each Snap.
References
Checklist
Note
Batch
OnAssetsConversion
andOnAssetsMarketData
per Snap across accounts with deduplicated assets; refactor controller, update tests, and note in changelog.#addAssetsToSnapIdMap
, deduplicating assets before calling Snaps.#getConversionRates
,#getMarketData
, and consolidated#getUpdatedRatesFor
combining both; added#getCaipCurrentCurrency
.#handleSnapRequest
with typed overloads; state merge via#applyUpdatedRates
now keyed byCaipAssetType
.updateAssetsRates
and#updateAssetsRatesForNewAssets
now build a Snap‑ID→assets map and issue a single batched call per Snap.swift:0/iso4217:USD
); add multi‑Snap scenarios and revised spies/mocks.OnAssetConversion
andOnAssetsMarketData
requests to non‑EVM account Snaps.Written by Cursor Bugbot for commit fd1be26. This will update automatically on new commits. Configure here.